package com.loves.common;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;

public class test {

    public static void main(String[] args) {
        //dateTest(LocalDate.of(2017, 10, 22),LocalDate.of(2018, 04, 22));
        a();
    }

    public static void dateTest(LocalDate start, LocalDate end){
        int startYear = start.getYear();
        int startMonth = start.getMonthValue();
        int endYear = end.getYear();
        int endMonth = end.getMonthValue();
        long yearNumber = endYear - startYear;
        for (int i = 0; i <= yearNumber; i++) {
            int jLength = startYear+i == endYear ? endMonth : 12;
            for (int j = startMonth; j <= jLength; j++) {
                String m = j<10 ? "0"+j: String.valueOf(j);
                System.out.println(startYear+i+"-"+m);
            }
            startMonth = 1;
        }
    }

    public static void a() {
        List<String> list = new ArrayList<>();
        LocalDate startTime = LocalDate.parse("2015-01-04");
        LocalDate endTime = LocalDate.parse("2016-11-06");
        while (startTime.getYear() <= endTime.getYear()) {
            String dt = startTime.format(DateTimeFormatter.ofPattern("yyyy-MM"));
            list.add(dt);
            startTime = startTime.plusMonths(1);
            if (startTime.getYear() == endTime.getYear() && startTime.getMonthValue() > endTime.getMonthValue()) {
                break;
            }
        }
        System.out.println(list);
    }

}
